<template>
  <div class="outdoor-activity-survey">
    <div class="header">
      <h1>{{ surveyConfig.title }}</h1>
      <p class="subtitle">{{ surveyConfig.subtitle }}</p>
      <div class="header-actions">
        <button @click="goToHome" class="home-btn">
          <span class="home-icon">🏠</span> {{ surveyConfig.ui.buttons.home }}
        </button>
        <button @click="showSettings = true" class="settings-btn">
          <span class="settings-icon">⚙️</span> {{ surveyConfig.ui.buttons.settings }}
        </button>
      </div>
    </div>

    <!-- 设置页面 -->
    <div class="settings-modal" v-if="showSettings">
      <div class="settings-content">
        <div class="settings-header">
          <h2>{{ surveyConfig.settings.title }}</h2>
          <button @click="closeSettings" class="close-btn">×</button>
        </div>

        <div class="settings-form">
          <div class="form-group">
            <label>问答编号：<span class="required">*</span></label>
            <input type="text" v-model="recorderInfo.surveyId" placeholder="请输入问答编号（用于区分不同组的问卷）" maxlength="20">
            <p class="field-hint">编号用于区分不同组的问卷，建议使用如：OUTDOOR001、ACTIVITY_A等格式</p>
          </div>
          <div class="form-group">
            <label>记录人姓名：<span class="required">*</span></label>
            <input type="text" v-model="recorderInfo.name" placeholder="请输入记录人姓名">
          </div>
          <div class="form-group">
            <label>记录人职务/身份：<span class="required">*</span></label>
            <input type="text" v-model="recorderInfo.position" placeholder="请输入职务或身份（如：医生、护士、研究员等）">
          </div>
          <div class="form-group">
            <label>所属机构：</label>
            <input type="text" v-model="recorderInfo.institution" placeholder="请输入所属医院或机构名称">
          </div>
          <div class="form-group">
            <label>联系方式：</label>
            <input type="text" v-model="recorderInfo.contact" placeholder="请输入联系电话或邮箱">
          </div>
          <div class="form-group">
            <label>默认备注：</label>
            <textarea v-model="recorderInfo.defaultRemarks" placeholder="请输入默认备注信息（可选）" rows="3"></textarea>
          </div>
        </div>

        <div class="settings-actions">
          <button @click="saveRecorderInfo" class="save-settings-btn">保存设置</button>
          <button @click="closeSettings" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 记录人信息显示 -->
    <div class="recorder-info-display" v-if="recorderInfo.name && !showSettings && !showResult && !showExport">
      <div class="recorder-card">
        <div class="recorder-main-info">
          <h3>问答编号：{{ recorderInfo.surveyId }}</h3>
          <p>记录人：{{ recorderInfo.name }} | {{ recorderInfo.position }}</p>
          <p v-if="recorderInfo.institution">{{ recorderInfo.institution }}</p>
        </div>
        <div class="recorder-actions">
          <button @click="showSettings = true" class="edit-recorder-btn">编辑</button>
          <button @click="showExportDialog" class="export-btn">{{ surveyConfig.ui.buttons.export }}</button>
        </div>
      </div>
    </div>

    <!-- 导出数据模态框 -->
    <div class="export-modal" v-if="showExport">
      <div class="export-content">
        <div class="export-header">
          <h2>{{ surveyConfig.export.title }}</h2>
          <button @click="closeExport" class="close-btn">×</button>
        </div>

        <div class="export-form">
          <div class="export-info">
            <p><strong>当前问答编号：</strong>{{ recorderInfo.surveyId }}</p>
            <p><strong>导出说明：</strong>将从服务器打包当前编号的所有户外活动记录数据</p>
          </div>

          <div class="form-group">
            <label>导出密码：<span class="required">*</span></label>
            <input type="password" v-model="exportPassword" placeholder="请输入导出密码" @keyup.enter="exportData">
            <p class="field-hint">请联系管理员获取导出密码</p>
          </div>

          <div class="export-options">
            <div class="form-group">
              <label>
                <input type="checkbox" v-model="exportOptions.includeRawData">
                包含原始评估数据
              </label>
            </div>
            <div class="form-group">
              <label>
                <input type="checkbox" v-model="exportOptions.includeStatistics">
                包含统计分析
              </label>
            </div>
          </div>
        </div>

        <div class="export-actions">
          <button @click="exportData" class="export-confirm-btn" :disabled="!exportPassword">
            <span v-if="!isExporting">导出压缩包</span>
            <span v-else>导出中...</span>
          </button>
          <button @click="closeExport" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 表单 -->
    <div class="survey-form" v-if="!showResult && !showSettings && !showExport">
      <p class="instruction">{{ surveyConfig.instruction }}</p>

      <!-- 基本信息 -->
      <div class="section">
        <h2>{{ surveyConfig.sections.basicInfo.title }}</h2>
        <div class="form-grid">
          <div class="form-group" v-for="field in surveyConfig.sections.basicInfo.fields" :key="field.name">
            <label>{{ field.label }}：<span v-if="field.required" class="required">*</span></label>
            <input
              v-if="field.type === 'text' || field.type === 'number' || field.type === 'tel' || field.type === 'date'"
              :type="field.type" v-model="formData[field.name]" :placeholder="field.placeholder" :min="field.min"
              :max="field.max" :step="field.step">
            <textarea v-else-if="field.type === 'textarea'" v-model="formData[field.name]"
              :placeholder="field.placeholder" :rows="field.rows"></textarea>
            <div v-else-if="field.type === 'radio'" class="radio-group">
              <label v-for="option in field.options" :key="option.value">
                <input type="radio" v-model="formData[field.name]" :value="option.value"> {{ option.label }}
              </label>
            </div>
          </div>
        </div>
      </div>

      <!-- 活动记录 -->
      <div class="section">
        <h2>{{ surveyConfig.sections.activityRecord.title }}</h2>
        <p class="assessment-description">{{ surveyConfig.sections.activityRecord.description }}</p>
        
        <!-- 活动分类说明 -->
        <div class="info-box">
          <h4>活动分类说明：</h4>
          <ul>
            <li v-for="category in surveyConfig.activityCategories" :key="category.value">
              {{ category.value }}. {{ category.label }}
            </li>
          </ul>
        </div>

        <!-- 活动记录列表 -->
        <div class="activities-container">
          <div v-for="index in activityCount" :key="index" class="activity-item">
            <div class="activity-header">
              <h3>活动记录 {{ index }}</h3>
              <button 
                v-if="activityCount > 1" 
                @click="removeActivity(index)" 
                class="remove-activity-btn"
                type="button">
                {{ surveyConfig.ui.buttons.removeActivity }}
              </button>
            </div>
            
            <div class="activity-form">
              <div class="form-row">
                <div class="form-group">
                  <label>户外行为编号：<span class="required">*</span></label>
                  <input 
                    type="text" 
                    v-model="formData[`activityCode_${index}`]" 
                    :placeholder="surveyConfig.ui.placeholders.activityCode">
                </div>
                <div class="form-group">
                  <label>活动分类：</label>
                  <select v-model="formData[`activityCategory_${index}`]">
                    <option value="">请选择</option>
                    <option 
                      v-for="category in surveyConfig.activityCategories" 
                      :key="category.value" 
                      :value="category.value">
                      {{ category.value }}. {{ category.label }}
                    </option>
                  </select>
                </div>
              </div>

              <div class="form-row">
                <div class="form-group">
                  <label>开始时间：</label>
                  <input 
                    type="datetime-local" 
                    v-model="formData[`startTime_${index}`]" 
                    :placeholder="surveyConfig.ui.placeholders.startTime">
                </div>
                <div class="form-group">
                  <label>步行时长(min)：</label>
                  <input 
                    type="number" 
                    v-model="formData[`duration_${index}`]" 
                    :placeholder="surveyConfig.ui.placeholders.duration"
                    min="0"
                    step="1">
                </div>
              </div>

              <div class="form-row">
                <div class="form-group">
                  <label>活动场所：</label>
                  <input 
                    type="text" 
                    v-model="formData[`venue_${index}`]" 
                    :placeholder="surveyConfig.ui.placeholders.venue"
                    list="venue-list">
                  <datalist id="venue-list">
                    <option v-for="venue in surveyConfig.activityVenues" :key="venue" :value="venue"></option>
                  </datalist>
                </div>
                <div class="form-group">
                  <label>使用物品：</label>
                  <input 
                    type="text" 
                    v-model="formData[`itemsUsed_${index}`]" 
                    :placeholder="surveyConfig.ui.placeholders.items"
                    list="items-list">
                  <datalist id="items-list">
                    <option v-for="item in surveyConfig.itemsUsed" :key="item" :value="item"></option>
                  </datalist>
                </div>
              </div>

              <div class="form-row">
                <div class="form-group">
                  <label>
                    <input 
                      type="checkbox" 
                      v-model="formData[`isWeekend_${index}`]"> 
                    周末
                  </label>
                </div>
                <div class="form-group full-width">
                  <label>路线：</label>
                  <textarea 
                    v-model="formData[`route_${index}`]" 
                    :placeholder="surveyConfig.ui.placeholders.route"
                    rows="2"></textarea>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 添加活动按钮 -->
        <div class="add-activity-section" v-if="activityCount < surveyConfig.maxActivities">
          <button @click="addActivity" class="add-activity-btn" type="button">
            + {{ surveyConfig.ui.buttons.addActivity }}
          </button>
        </div>
        <div v-else class="max-activities-hint">
          <p>已达到最大活动记录数（{{ surveyConfig.maxActivities }}条）</p>
        </div>
      </div>

      <!-- 提交按钮 -->
      <div class="form-actions">
        <button @click="calculateResult" class="submit-btn" :disabled="!isFormValid">
          {{ surveyConfig.ui.buttons.submit }}
        </button>
      </div>
    </div>

    <!-- 结果展示 -->
    <div class="result-section" v-if="showResult">
      <h2>户外活动记录结果</h2>
      <div class="result-card">
        <div class="result-summary">
          <h3>记录完成</h3>
          <p class="total-activities">总活动数：{{ result.totalActivities }} 条</p>
        </div>

        <div class="result-details">
          <h4>统计信息：</h4>
          <ul>
            <li>总活动数：{{ result.totalActivities }} 条</li>
            <li>总步行时长：{{ result.statistics.totalDuration }} 分钟</li>
            <li>平均步行时长：{{ result.statistics.averageDuration }} 分钟</li>
            <li>周末活动：{{ result.statistics.weekendActivities }} 条</li>
            <li>工作日活动：{{ result.statistics.weekdayActivities }} 条</li>
            <li v-if="result.summary.mainActivityType">主要活动类型：{{ result.summary.mainActivityType }}</li>
            <li v-if="result.summary.mainVenue">主要活动场所：{{ result.summary.mainVenue }}</li>
          </ul>
        </div>

        <div class="action-buttons">
          <button @click="saveToBackendOnly" class="save-btn" :disabled="isSaving">
            <span v-if="!isSaving">保存结果</span>
            <span v-else>保存中...</span>
          </button>
          <button @click="resetForm" class="reset-btn">{{ surveyConfig.ui.buttons.restart }}</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { outdoorActivityConfig } from '@/config/outdoorActivityConfig.js';
import { calculateOutdoorActivityAssessment } from '@/config/outdoorActivityLogic.js';

export default {
  name: 'OutdoorActivitySurvey',
  mounted() {
    // 自动设置当前日期
    const now = new Date();
    const year = now.getFullYear();
    const month = String(now.getMonth() + 1).padStart(2, '0');
    const day = String(now.getDate()).padStart(2, '0');
    this.formData.recordDate = `${year}-${month}-${day}`;

    // 加载记录人信息
    this.loadRecorderInfo();

    // 初始化表单数据
    this.initializeForm();
  },
  data() {
    return {
      surveyConfig: outdoorActivityConfig,
      showResult: false,
      showSettings: false,
      showExport: false,
      isExporting: false,
      isSaving: false,
      exportPassword: '',
      activityCount: 1, // 活动记录数量
      // 记录人信息（设置）
      recorderInfo: {
        surveyId: '',
        name: '',
        position: '',
        institution: '',
        contact: '',
        defaultRemarks: ''
      },
      // 导出选项
      exportOptions: {
        includeRawData: true,
        includeStatistics: true
      },
      // 问卷表单数据
      formData: {},
      result: {
        activities: [],
        statistics: {},
        summary: {},
        totalActivities: 0
      }
    }
  },
  computed: {
    isFormValid() {
      // 检查基本信息
      if (!this.recorderInfo.surveyId || !this.recorderInfo.name || !this.recorderInfo.position) {
        return false;
      }
      // 个人信息字段已改为选填，不再进行必填验证
      
      // 检查至少有一条活动记录
      let hasActivity = false;
      for (let i = 1; i <= this.activityCount; i++) {
        if (this.formData[`activityCode_${i}`] && this.formData[`activityCode_${i}`].trim() !== '') {
          hasActivity = true;
          break;
        }
      }
      
      return hasActivity;
    }
  },
  methods: {
    // 导航方法
    goToHome() {
      this.$router.push('/');
    },

    // 初始化表单数据
    initializeForm() {
      // 保留已设置的recordDate值
      const existingRecordDate = this.formData.recordDate;

      this.formData = {
        recordDate: existingRecordDate || ''
      };
    },

    // 添加活动记录
    addActivity() {
      if (this.activityCount < this.surveyConfig.maxActivities) {
        this.activityCount++;
      }
    },

    // 删除活动记录
    removeActivity(index) {
      if (this.activityCount <= 1) {
        return;
      }
      
      // 删除对应索引的数据
      for (let i = index; i < this.activityCount; i++) {
        const nextIndex = i + 1;
        this.formData[`activityCode_${i}`] = this.formData[`activityCode_${nextIndex}`] || '';
        this.formData[`activityCategory_${i}`] = this.formData[`activityCategory_${nextIndex}`] || '';
        this.formData[`startTime_${i}`] = this.formData[`startTime_${nextIndex}`] || '';
        this.formData[`duration_${i}`] = this.formData[`duration_${nextIndex}`] || '';
        this.formData[`venue_${i}`] = this.formData[`venue_${nextIndex}`] || '';
        this.formData[`itemsUsed_${i}`] = this.formData[`itemsUsed_${nextIndex}`] || '';
        this.formData[`isWeekend_${i}`] = this.formData[`isWeekend_${nextIndex}`] || false;
        this.formData[`route_${i}`] = this.formData[`route_${nextIndex}`] || '';
      }
      
      // 清除最后一条记录
      const lastIndex = this.activityCount;
      this.formData[`activityCode_${lastIndex}`] = '';
      this.formData[`activityCategory_${lastIndex}`] = '';
      this.formData[`startTime_${lastIndex}`] = '';
      this.formData[`duration_${lastIndex}`] = '';
      this.formData[`venue_${lastIndex}`] = '';
      this.formData[`itemsUsed_${lastIndex}`] = '';
      this.formData[`isWeekend_${lastIndex}`] = false;
      this.formData[`route_${lastIndex}`] = '';
      
      this.activityCount--;
    },

    // 设置相关方法
    saveRecorderInfo() {
      // 验证必填字段
      if (!this.recorderInfo.surveyId || !this.recorderInfo.name || !this.recorderInfo.position) {
        alert('请填写所有必填信息（问答编号、记录人姓名、职务/身份）！');
        return;
      }

      // 保存记录人信息到本地存储
      localStorage.setItem('outdoorActivityRecorderInfo', JSON.stringify(this.recorderInfo));
      // 设置默认备注
      if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
        this.formData.remarks = this.recorderInfo.defaultRemarks;
      }
      this.showSettings = false;
      alert('记录人信息已保存！');
    },

    closeSettings() {
      this.showSettings = false;
    },

    loadRecorderInfo() {
      // 从本地存储加载记录人信息
      const saved = localStorage.getItem('outdoorActivityRecorderInfo');
      if (saved) {
        this.recorderInfo = JSON.parse(saved);
        // 设置默认备注
        if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
          this.formData.remarks = this.recorderInfo.defaultRemarks;
        }
      }
    },

    // 导出相关方法
    showExportDialog() {
      this.showExport = true;
      this.exportPassword = '';
    },

    closeExport() {
      this.showExport = false;
      this.exportPassword = '';
      this.isExporting = false;
    },

    async exportData() {
      this.isExporting = true;

      try {
        // 发送导出请求到服务器
        const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/export-outdoor-activity-survey`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            surveyId: this.recorderInfo.surveyId,
            password: this.exportPassword,
            exportOptions: this.exportOptions
          })
        });

        if (response.status === 401) {
          alert('密码错误，请重新输入！');
          return;
        }

        if (!response.ok) {
          throw new Error('导出请求失败');
        }

        // 获取服务器返回的压缩包
        const blob = await response.blob();

        if (blob.size === 0) {
          alert('当前问答编号下没有户外活动记录数据！');
          return;
        }

        // 下载服务器生成的压缩包
        const url = window.URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = url;
        link.download = `户外活动记录数据_${this.recorderInfo.surveyId}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.zip`;
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        window.URL.revokeObjectURL(url);

        alert('数据导出成功！');
        this.closeExport();
      } catch (error) {
        console.error('导出失败:', error);
        alert('导出失败，请检查网络连接或联系管理员！');
      } finally {
        this.isExporting = false;
      }
    },

    calculateResult() {
      // 使用户外活动评估逻辑
      this.result = calculateOutdoorActivityAssessment(this.formData);
      this.showResult = true;
    },

    async saveToBackendOnly() {
      this.isSaving = true;

      try {
        // 1. 保存问卷数据到后台
        await this.saveToBackend();

        // 2. 生成评估报告内容
        const timestamp = new Date().toLocaleString('zh-CN');
        const recordDate = this.formData.recordDate ?
          new Date(this.formData.recordDate).toLocaleString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric' }) :
          timestamp;

        const categoryLabels = {
          1: '买菜购物',
          2: '运动锻炼',
          3: '棋牌麻将',
          4: '接送孙辈',
          5: '唱歌跳舞',
          6: '休闲步行（如散步、逛公园、遛狗等）',
          7: '跑腿（如倒垃圾、取快递、取老人餐等）',
          8: '集体活动（如志愿活动、社区活动等）'
        };

        let activitiesText = '';
        this.result.activities.forEach(activity => {
          activitiesText += `\n活动 ${activity.index}：\n`;
          activitiesText += `  户外行为编号：${activity.activityCode}\n`;
          activitiesText += `  活动分类：${activity.category ? categoryLabels[activity.category] : '未分类'}\n`;
          activitiesText += `  开始时间：${activity.startTime || '未填写'}\n`;
          activitiesText += `  步行时长：${activity.duration ? activity.duration + '分钟' : '未填写'}\n`;
          activitiesText += `  活动场所：${activity.venue || '未填写'}\n`;
          activitiesText += `  使用物品：${activity.itemsUsed || '无'}\n`;
          activitiesText += `  周末：${activity.isWeekend ? '是' : '否'}\n`;
          activitiesText += `  路线：${activity.route || '未填写'}\n`;
        });

        const content = `户外活动记录结果报告
问答编号：${this.recorderInfo.surveyId}
生成时间：${timestamp}

=== 记录人信息 ===
记录人姓名：${this.recorderInfo.name}
记录人职务/身份：${this.recorderInfo.position}
所属机构：${this.recorderInfo.institution || '未填写'}
联系方式：${this.recorderInfo.contact || '未填写'}
记录日期：${recordDate}
备注：${this.formData.remarks || '无'}

=== 被评估人基本信息 ===
姓名：${this.formData.patientName}
编号：${this.formData.patientId || '未填写'}
日期：${recordDate}
居住地址：${this.formData.residenceAddress}
年龄：${this.formData.age || '未填写'}岁
性别：${this.formData.gender === 'male' ? '男性' : this.formData.gender === 'female' ? '女性' : '未填写'}
联系电话：${this.formData.phone || '未填写'}

=== 户外活动记录 ===
总活动数：${this.result.totalActivities} 条
总步行时长：${this.result.statistics.totalDuration} 分钟
平均步行时长：${this.result.statistics.averageDuration} 分钟
周末活动：${this.result.statistics.weekendActivities} 条
工作日活动：${this.result.statistics.weekdayActivities} 条
主要活动类型：${this.result.summary.mainActivityType || '无'}
主要活动场所：${this.result.summary.mainVenue || '无'}
${activitiesText}

报告结束
`;

        // 3. 保存评估报告到@data/文件夹
        await this.saveFileToDataFolder(content);

        alert('✅ 数据已成功保存到后台！\n\n📁 问卷数据：survey_data/\n📄 评估报告：@data/');

      } catch (error) {
        console.error('保存到后台失败:', error);
        alert('❌ 保存失败，请检查网络连接或联系管理员！\n\n错误信息：' + error.message);
      } finally {
        this.isSaving = false;
      }
    },

    async saveToBackend() {
      // 构建问卷数据
      const surveyData = {
        surveyId: this.recorderInfo.surveyId,
        recordTime: new Date().toISOString(),
        recordDate: this.formData.recordDate,
        recorderName: this.recorderInfo.name,
        recorderPosition: this.recorderInfo.position,
        recorderInstitution: this.recorderInfo.institution,
        recorderContact: this.recorderInfo.contact,
        patientName: this.formData.patientName || "未填写",
        patientId: this.formData.patientId,
        residenceAddress: this.formData.residenceAddress,
        age: this.formData.age || 0,
        gender: this.formData.gender,
        phone: this.formData.phone,
        remarks: this.formData.remarks,
        // 活动记录数据
        activities: [],
        // 计算结果
        totalActivities: this.result.totalActivities,
        statistics: this.result.statistics,
        summary: this.result.summary,
        createdAt: new Date().toISOString()
      };

      // 添加活动记录
      for (let i = 1; i <= this.activityCount; i++) {
        const activityCode = this.formData[`activityCode_${i}`];
        if (activityCode && activityCode.trim() !== '') {
          surveyData.activities.push({
            index: i,
            activityCode: activityCode,
            category: this.formData[`activityCategory_${i}`] || null,
            startTime: this.formData[`startTime_${i}`] || '',
            duration: this.formData[`duration_${i}`] ? parseFloat(this.formData[`duration_${i}`]) : null,
            venue: this.formData[`venue_${i}`] || '',
            itemsUsed: this.formData[`itemsUsed_${i}`] || '',
            isWeekend: this.formData[`isWeekend_${i}`] || false,
            route: this.formData[`route_${i}`] || ''
          });
        }
      }

      const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-outdoor-activity-survey`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(surveyData)
      });

      if (!response.ok) {
        throw new Error('保存问卷数据失败');
      }
    },

    async saveFileToDataFolder(content) {
      // 通过API保存文件到@data/文件夹
      const filename = `户外活动记录结果_${this.recorderInfo.surveyId}_${this.formData.patientName}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.txt`;

      const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-file`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          filename: filename,
          content: content,
          surveyId: this.recorderInfo.surveyId
        })
      });

      if (!response.ok) {
        throw new Error('保存评估报告失败');
      }
    },

    resetForm() {
      this.formData = {};
      this.activityCount = 1;
      this.result = {
        activities: [],
        statistics: {},
        summary: {},
        totalActivities: 0
      };
      this.showResult = false;
      // 重新设置日期
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, '0');
      const day = String(now.getDate()).padStart(2, '0');
      this.formData.recordDate = `${year}-${month}-${day}`;
    }
  }
}
</script>

<style scoped>
.outdoor-activity-survey {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.header {
  text-align: center;
  margin-bottom: 30px;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.header h1 {
  margin: 0 0 10px 0;
  font-size: 2.5em;
  font-weight: 300;
}

.subtitle {
  margin: 0 0 20px 0;
  font-size: 1.2em;
  opacity: 0.9;
}

.header-actions {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.home-btn,
.settings-btn {
  padding: 10px 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.home-btn:hover,
.settings-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

/* 设置模态框样式 */
.settings-modal,
.export-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.settings-content,
.export-content {
  background: white;
  padding: 30px;
  border-radius: 15px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.settings-header,
.export-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #f0f0f0;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 5px;
  border-radius: 50%;
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: #f0f0f0;
  color: #333;
}

/* 记录人信息显示 */
.recorder-info-display {
  margin-bottom: 30px;
}

.recorder-card {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 4px solid #667eea;
}

.recorder-main-info h3 {
  margin: 0 0 5px 0;
  color: #333;
}

.recorder-main-info p {
  margin: 5px 0;
  color: #666;
}

.recorder-actions {
  display: flex;
  gap: 10px;
}

.edit-recorder-btn,
.export-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.edit-recorder-btn:hover {
  background: #f0f0f0;
}

.export-btn {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.export-btn:hover {
  background: #5568d3;
}

/* 表单样式 */
.survey-form {
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.instruction {
  font-size: 1.1em;
  color: #666;
  margin-bottom: 30px;
  padding: 15px;
  background: #f8f9fa;
  border-left: 4px solid #667eea;
  border-radius: 5px;
}

.section {
  margin-bottom: 40px;
}

.section h2 {
  color: #333;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #667eea;
}

.assessment-description {
  color: #666;
  margin-bottom: 15px;
}

.info-box {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 5px;
  margin-bottom: 20px;
  border-left: 4px solid #667eea;
}

.info-box h4 {
  margin: 0 0 10px 0;
  color: #333;
}

.info-box ul {
  margin: 0;
  padding-left: 20px;
  color: #666;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #333;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
  box-sizing: border-box;
}

.form-group textarea {
  resize: vertical;
}

.required {
  color: #e74c3c;
}

.field-hint {
  font-size: 12px;
  color: #999;
  margin-top: 5px;
}

.radio-group {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: normal;
}

/* 活动记录样式 */
.activities-container {
  margin-bottom: 20px;
}

.activity-item {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 20px;
  border: 2px solid #e9ecef;
}

.activity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid #dee2e6;
}

.activity-header h3 {
  margin: 0;
  color: #333;
  font-size: 1.2em;
}

.remove-activity-btn {
  padding: 6px 12px;
  background: #dc3545;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
}

.remove-activity-btn:hover {
  background: #c82333;
}

.activity-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.form-row .form-group.full-width {
  grid-column: 1 / -1;
}

.add-activity-section {
  text-align: center;
  margin: 20px 0;
}

.add-activity-btn {
  padding: 12px 24px;
  background: #28a745;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s ease;
}

.add-activity-btn:hover {
  background: #218838;
}

.max-activities-hint {
  text-align: center;
  padding: 15px;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 5px;
  color: #856404;
}

/* 按钮样式 */
.form-actions {
  text-align: center;
  margin-top: 30px;
}

.submit-btn {
  padding: 15px 40px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.3s ease;
}

.submit-btn:hover:not(:disabled) {
  background: #5568d3;
  transform: translateY(-2px);
}

.submit-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* 结果展示样式 */
.result-section {
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.result-section h2 {
  color: #333;
  margin-bottom: 20px;
  text-align: center;
}

.result-card {
  background: #f8f9fa;
  padding: 30px;
  border-radius: 10px;
  border-left: 4px solid #667eea;
}

.result-summary {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid #dee2e6;
}

.result-summary h3 {
  color: #667eea;
  margin-bottom: 10px;
}

.total-activities {
  font-size: 1.2em;
  color: #666;
}

.result-details {
  margin-bottom: 20px;
}

.result-details h4 {
  color: #333;
  margin-bottom: 10px;
}

.result-details ul {
  list-style: none;
  padding: 0;
}

.result-details li {
  padding: 8px 0;
  border-bottom: 1px solid #e9ecef;
  color: #666;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 30px;
}

.save-btn,
.reset-btn {
  padding: 12px 30px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s ease;
}

.save-btn {
  background: #28a745;
  color: white;
}

.save-btn:hover:not(:disabled) {
  background: #218838;
}

.save-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.reset-btn {
  background: #6c757d;
  color: white;
}

.reset-btn:hover {
  background: #5a6268;
}

/* 设置表单样式 */
.settings-form {
  margin-bottom: 20px;
}

.settings-actions,
.export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.save-settings-btn,
.export-confirm-btn {
  padding: 10px 20px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.save-settings-btn:hover,
.export-confirm-btn:hover:not(:disabled) {
  background: #5568d3;
}

.export-confirm-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.cancel-btn {
  padding: 10px 20px;
  background: #6c757d;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.cancel-btn:hover {
  background: #5a6268;
}

.export-info {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 5px;
  margin-bottom: 20px;
}

.export-info p {
  margin: 5px 0;
  color: #666;
}

.export-options {
  margin-top: 15px;
}

.export-options .form-group {
  margin-bottom: 10px;
}

.export-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: normal;
}
</style>

